package com.example.teaculture.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.teaculture.DB.AdviceSQL;
import com.example.teaculture.R;

import java.util.ArrayList;
import java.util.HashMap;

public class AdviceActivity extends Activity {
    private EditText advice_content;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_advice);
        AdviceSQL.initTable(AdviceActivity.this);
        //获取按钮
        Button but_help_feedback=(Button)findViewById(R.id.but_help_feedback);
        advice_content=(EditText)findViewById(R.id.help_feedback);

        //添加点击事件 ，保存文本信息，并生成提示
        but_help_feedback.setOnClickListener(new Button.OnClickListener()
        {
            public void onClick(View v){
                String Context =advice_content.getText().toString();
                try{
                    AdviceSQL function = new AdviceSQL();
                    Object[] data = {Context};
                    function.insert(AdviceActivity.this,data);

                    Toast.makeText(AdviceActivity.this, "感谢您的反馈,我们会尽快处理您的意见。", Toast.LENGTH_SHORT).show();
                    advice_content.setText("");

                    //在控制台输出数据库数据
                    Log.i("TAG:","查询数据！");
                    ArrayList<HashMap<String ,String>> list;
                    list = function.query(AdviceActivity.this);
                    if(list!=null){
                        Log.i("TAG:","从数据库中拿到的数据advice为：");
                        for(int i = 0 ; i<list.size();i++){
                            Log.i("TAG:","    " +list.get(i).get("advice"));
                        }
                    }else {
                        Log.i("TAG:","从数据库中没有拿到数据！");
                    }

                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
                finally{

                }
            }
        });

    }
public void aback(View view){
  this.finish();
}
}
